<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/10/30
 * Time: 13:20
 */

namespace Admin\Controller;
use Think\Controller;
class RoomController extends Controller
{
    public static $room_type =  array(
        "StandardSingle"=>"标准单人房",
        "StandardDouble"=>"标准双人房",
        "LuxuriousSingle"=>"豪华单人房",
        "LuxuriousDouble"=>"豪华双人房",
    );
    public function index()
    {
        $this->checkSession();
        $this->display();
    }

    public function info(){
        $this->checkSession();
        if (IS_POST) {
            $startDate = $_POST['startDate'];//提取用户名
            $endDate = $_POST['endDate']; // 提取密码并进行加密
           // $category = self::$room_type[$_POST['category']];

            $StandardSingle="标准单人房";
            $StandardDouble="标准双人房";
            $LuxuriousSingle="豪华单人房";
            $LuxuriousDouble="豪华双人房";

            //标准单人房
            $StandardSingle_wait_order =M('room_order')->where("endtime='$endDate'and starttime='$startDate'and order_status='到店付'and category='$StandardSingle'")->count();//等待付款
            $StandardSingle_pay_order =M('room_order')->where("endtime='$endDate'and starttime='$startDate'and order_status='已支付'and category='$StandardSingle'")->count();//已付款
            $StandardSingle_all =M("room")->where("room_category='$StandardSingle'")->count();
            $StandardSingle_sum=$StandardSingle_all-$StandardSingle_wait_order-$StandardSingle_pay_order;

            $this->assign('StandardSingle_sum',$StandardSingle_sum);

            //标准双人房
            $StandardDouble_wait_order =M('room_order')->where("endtime='$endDate'and starttime='$startDate'and order_status='到店付'and category='$StandardDouble'")->count();
            $StandardDouble_pay_order =M('room_order')->where("endtime='$endDate'and starttime='$startDate'and order_status='已支付'and category='$StandardDouble'")->count();
            $StandardDouble_all =M("room")->where("room_category='$StandardDouble'")->count();
            $StandardDouble_sum=$StandardDouble_all-$StandardDouble_wait_order-$StandardDouble_pay_order;

            $this->assign('StandardDouble_sum',$StandardDouble_sum);

            //豪华单人房
            $LuxuriousSingle_wait_order =M('room_order')->where("endtime='$endDate'and starttime='$startDate'and order_status='到店付'and category='$LuxuriousSingle'")->count();
            $LuxuriousSingle_pay_order =M('room_order')->where("endtime='$endDate'and starttime='$startDate'and order_status='已支付'and category='$LuxuriousSingle'")->count();
            $LuxuriousSingle_all =M("room")->where("room_category='$LuxuriousSingle'")->count();
            $LuxuriousSingle_sum=$LuxuriousSingle_all-$LuxuriousSingle_wait_order-$LuxuriousSingle_pay_order;
            //($LuxuriousSingle_sum);
            $this->assign('LuxuriousSingle_sum',$LuxuriousSingle_sum);

            //豪华双人房
            $LuxuriousDouble_wait_order =M('room_order')->where("endtime='$endDate'and starttime='$startDate'and order_status='到店付'and category='$LuxuriousDouble'")->count();
            $LuxuriousDouble_pay_order =M('room_order')->where("endtime='$endDate'and starttime='$startDate'and order_status='已支付'and category='$LuxuriousDouble'")->count();
            $LuxuriousDouble_all =M("room")->where("room_category='$LuxuriousDouble'")->count();
            $LuxuriousDouble_sum=$LuxuriousDouble_all-$LuxuriousDouble_wait_order-$LuxuriousDouble_pay_order;

            $this->assign('LuxuriousDouble_sum',$LuxuriousDouble_sum);

        $this->display();
        }}
    public function notice(){
        $this->checkSession();
        $now = date('Y-m-d');



        $record = M('room_order');
        if ($order =$record->where("instatus='已入住'and endtime='$now'")->count()) {
            $per = 5;
            import('Org.Util.Page');
            $page = new \Page($order,$per);
            $sql = "select * from hotel_room_order where instatus='已入住' AND endtime='$now'".$page->limit;//显示订单入住时间在今天以及之后的
            $query = $record -> query($sql);
            $pageList=$page->fpage();
            $this->assign('param',$query);
            $this->assign('pageList',$pageList);
            $this->assign('num',1);
        }


        $this->display();
    }
    public function notice_record(){//到期应退房客户
        /*  $admin = $_SESSION['admin'];
          if(!isset($admin)&&is_null($admin)){
              $this->error('请重新登陆','../Login/index');
          }*/
        $this->checkSession();
        $now = date('Y-m-d');
        $str = $_POST['keyword'];
        if(empty($str)||is_null($str)){
            $this->recordList_order();
        }
        else{$order = M('room_order');
            $key = '%'.$str.'%';
            $map['room_id']=array('like',$key);
            $total = $order->where($map)->count();
            $per = 8;
            import('Org.Util.Page');
            $page = new \Page($total,$per);
            $sql = "select * from hotel_room_order where  instatus='已入住' AND endtime='$now' AND (room_id like '%".$str."%' ) ".$page->limit;
            $query = $order -> query($sql);
            $pageList=$page->fpage();
            $this->assign('param',$query);
            $this->assign('pageList',$pageList);
            $this->assign('num',1);
        }
        $this->display('notice_record');
    }
    public function recordList_order(){
        $this->checkSession();
        $now = date('Y-m-d');
        $record = M('room_order');
        $total=$record->count();
        $per = 15;
        import('Org.Util.Page');
        $page = new \Page($total,$per);
        $sql = "select * from hotel_room_order where  instatus='已入住' AND endtime='$now'".$page->limit;
        $query = $record -> query($sql);
        $pageList=$page->fpage();
        $this->assign('param',$query);
        $this->assign('pageList',$pageList);
        $this->assign('num',1);
    }
    public function checkSession(){
        $employe_id = $_SESSION['employe_id'];
        if(isset($employe_id)){
            $this->assign('employe_id',$employe_id);
        }else{
            $this->error("需先登录,方可进行查询！",U('Login/index'));
        }
    }
}